/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.gps.record;

/**
 *
 * @author romulogalindo
 */
public class Record_GT06N extends Record {

    public Record_GT06N() {
        posicion = new RecordPosicion();
        estado = new RecordEstado();
        alarma = new RecordAlarma();
    }

    @Override
    public String getQuery() {
        String sql = "";
        try {
//            System.out.println("@@type:" + type);
            switch (type) {
                case 2:
                case 3:
                case 4: {
                    sql = "select * from gpsveh.plposdis_co_imedis(p_co_disgps, p_fe_capgps::timestamp with time zone, p_nu_geolat, p_nu_geolon, p_nu_geoalt::smallint, p_nu_geodir::smallint, p_nu_geovel::smallint, p_nu_geokmt, p_va_sengps::character, p_va_sengsm::character, p_il_batdis, p_pr_batdis::smallint, p_il_blodis)";
                    sql = sql.replace("p_fe_capgps", posicion.getFecha() != null ? "'" + posicion.getFecha() + "'" : "null");
                    sql = sql.replace("p_co_disgps", "\'" + getId() + "\'");
                    sql = sql.replace("p_nu_geolat", "" + posicion.getLatitud());
                    sql = sql.replace("p_nu_geolon", "" + posicion.getLongitud());
                    sql = sql.replace("p_nu_geoalt", "" + posicion.getAltitud());
                    sql = sql.replace("p_nu_geodir", "" + posicion.getDireccion());
                    sql = sql.replace("p_nu_geovel", "" + posicion.getVelocidad());
                    sql = sql.replace("p_nu_geokmt", estado.getKilometraje() != null ? "" + estado.getKilometraje() : "0");
                    sql = sql.replace("p_va_sengps", estado.getSenal_gps() != null ? "'" + estado.getSenal_gps() + "'" : "'F'");
                    sql = sql.replace("p_va_sengsm", estado.getSenal_gsm() != null ? "'" + estado.getSenal_gsm() + "'" : "'F'");
                    sql = sql.replace("p_il_batdis", estado.getBatdis() != null ? "" + estado.getBatdis() : "false");
                    sql = sql.replace("p_pr_batdis", estado.getCarga_bateria() != null ? "" + estado.getCarga_bateria() : "'0'");
//                    sql = sql.replace("p_il_blodis", estado.getBloqueado() != null ? "" + estado.getBloqueado() : "false");
                    sql = sql.replace("p_il_blodis", estado.getBloqueado()+"");
                    break;
                }
                case 5:
                case 6:
                case 7:
                case 8: {
                    sql = "select * from gpsveh.plevedis_co_imedis(p_co_imedis, p_fe_evegps::timestamp with time zone, p_co_evedis::smallint)";
                    sql = sql.replace("p_co_imedis", getId() != null ? "'" + getId() + "'" : null);
                    sql = sql.replace("p_fe_evegps", posicion.getFecha() != null ? "'" + posicion.getFecha() + "'" : "null");
                    sql = sql.replace("p_co_evedis", alarma.getAlarma() + "");
                }

            }
//            if ((type == 2) | (type == 3) | (type == 4)) {
//            } else if ((type == 5) | (type == 6) | (type == 7) | (type == 8)) {
//            }
        } catch (Exception ep) {
            System.out.println("Error construyendo query:" + ep.getMessage() + "\n::sql:" + sql);
            ep.printStackTrace();
            return null;
        }
//        System.out.println("//==============================================================");
//        System.out.println("" + sql);
//        System.out.println("//==============================================================");
        return sql;
    }

}
